import {
	LOGIN_BY_CAPTCHA ,
	GET_CAPTCHA ,
	LOGIN_BY_PASSWORD ,
	REGISTER ,
	GET_USERINFO ,
	GET_NOTREAD ,
	GET_COUNTWISHVERIFY ,
	GET_INVITE ,
	GET_MESSAGE,
	SEARCH_USER_BY_ID ,
	ADD_FOLLOW ,
	CANCEL_FOLLOW ,
	ADD_CONTRACT ,
	GET_CONTRACT ,
	SELECT_FANS ,
	SELECT_BY_KEYWORD ,
	SELECT_FOLLOW ,
	SEARCH_FOLLOW ,
	
} from '../mutation-types'

import { $axios } from '@/utils/api'

const state = {
	user:[]
}

const getters = {

}

const actions = {
	[GET_CAPTCHA]: async ({ commit, state, rootState }, { data,onSuccess }) => {

	  const response = await $axios({
		url: `/user/verificationCode`,
		method: 'POST',
		data
	  })
	  onSuccess && onSuccess(response.data)
	},
	[LOGIN_BY_CAPTCHA]: async ({ commit, state, rootState }, { data,onSuccess }) => {
	    const response = await $axios({
	      url: `/user/loginByCode`,
	      method: 'POST',
		  data
	    })
	    onSuccess && onSuccess(response.data)
	  },
	[LOGIN_BY_PASSWORD]: async ({ commit, state, rootState }, { data,onSuccess }) => {
	    const response = await $axios({
	      url: `/user/login`,
	      method: 'POST',
		  data
	    })
	    onSuccess && onSuccess(response.data)
	  },
	[REGISTER]: async ({ commit, state, rootState }, { data,onSuccess }) => {
	    const response = await $axios({
	      url: `/user/register`,
	      method: 'POST',
		  data
	    })
	    onSuccess && onSuccess(response.data)
	  },
	[GET_USERINFO]: async ({ commit, state, rootState }, { data,onSuccess }) => {
		 console.log(data)
		 const response = await $axios({
		   url: `/user/userInfo?userId=${data.userId}`,
		   method: 'GET'
		 })
		 onSuccess && onSuccess(response.data)
		},
	[GET_NOTREAD]: async ({ commit, state, rootState }, {onSuccess }) => {
	      const response = await $axios({
	        url: `/message/notRead`,
	        method: 'GET',
	      })
	      onSuccess && onSuccess(response.data)
	    },
	[GET_COUNTWISHVERIFY]: async ({ commit, state, rootState }, {onSuccess }) => {
		    const response = await $axios({
		      url: `/wishing/countVerify`,
		      method: 'GET',
		    })
		    onSuccess && onSuccess(response.data)
		  },
	   [GET_INVITE]: async ({ commit, state, rootState }, {onSuccess }) => {
	   		    const response = await $axios({
	   		      url: `/invite/getInvite`,
	   		      method: 'GET',
	   		    })
	   		    onSuccess && onSuccess(response.data)
	   		  },
	[GET_MESSAGE]:async ({ commit, state, rootState }, { data,onSuccess }) => {
		const response = await $axios({
			url: `/message/selectByType?type=${data.type}&pageNum=${data.page}`,
			//url:`/message/selectByType`,
			method: 'GET'
		})
		onSuccess && onSuccess(response.data)
	},
    [SEARCH_USER_BY_ID]: async ({ commit, state, rootState }, {onSuccess ,data}) => {
        const response = await $axios({
            url: `/user/searchUser?name=${data.name}`,
            method: 'GET',
        })
        onSuccess && onSuccess(response.data)
    },
    [ADD_FOLLOW]: async ({ commit, state, rootState }, {onSuccess , data}) => {
        const response = await $axios({
            url: `/follow/addFollow`,
            method: 'POST',
        })
        onSuccess && onSuccess(response.data)
    },
    [CANCEL_FOLLOW]: async ({ commit, state, rootState }, {onSuccess , data}) => {
        const response = await $axios({
            url: `/follow/cancelFollow`,
            method: 'POST',
        })
        onSuccess && onSuccess(response.data)
    },
    [ADD_CONTRACT]: async ({ commit, state, rootState }, {onSuccess , data}) => {
        const response = await $axios({
            url: `/user/addContract`,
            method: 'POST',
        })
        onSuccess && onSuccess(response.data)
    },
    [GET_CONTRACT]: async ({ commit, state, rootState }, {onSuccess }) => {
        const response = await $axios({
            url: `/user/getContract`,
            method: 'GET',
        })
        onSuccess && onSuccess(response.data)
    },
    [SELECT_FANS]: async ({ commit, state, rootState }, {onSuccess ,data}) => {
        const response = await $axios({
            url: `/follow/selectFans`,
            method: 'GET',
        })
        onSuccess && onSuccess(response.data)
    },
    [SELECT_BY_KEYWORD]: async ({ commit, state, rootState }, {onSuccess ,data}) => {
        const response = await $axios({
            url: `/follow/selectFans?pageNum=${data.followId}`,
            method: 'GET',
        })
        onSuccess && onSuccess(response.data)
    },
    [SELECT_FOLLOW]: async ({ commit, state, rootState }, {onSuccess ,data}) => {
        const response = await $axios({
            url: `/follow/selectFollow?pageNum=${data.pageNum}`,
            method: 'GET',
        })
        onSuccess && onSuccess(response.data)
    },
    [SEARCH_FOLLOW]: async ({ commit, state, rootState }, {onSuccess ,data}) => {
        const response = await $axios({
            url: `/follow/searchFollow?name=${data.name}`,
            method: 'GET',
        })
        onSuccess && onSuccess(response.data)
    },
}

const mutations = {

}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
